#!/bin/sh

if [ $# -lt 1 ]
then
    echo "please input set_id to clean"
    exit
fi

MYSQL_IP=192.168.1.26
MYSQL_USER=root
MYSQL_PWD=qy22players
MYSQL_CMD=`echo mysql -h$MYSQL_IP -u$MYSQL_USER -p$MYSQL_PWD -e `

SET_ID=$1

echo "svr set_id is:$SET_ID   please enter [yes/no] to continu"

rm -rf /home/qie$SET_ID/code/run/sharecache/*.MMAP

echo "=========clear pg_account_db begin ========="

$MYSQL_CMD "USE pg_account_db;SHOW TABLES;" > tb1.txt
cat tb1.txt | grep -v 'Tables_in_pg_account_db' > tb2.txt
tb_list=`cat tb2.txt`
for tb in $tb_list
do
   $MYSQL_CMD "USE pg_account_db;DELETE FROM $tb WHERE set_id=$SET_ID;"
done
echo "---------clear pg_account_db end---------"




echo "=========clear pg_role_db begin ========="

$MYSQL_CMD "USE pg_role_db;SHOW TABLES;" > tb1.txt
cat tb1.txt | grep -v 'Tables_in_pg_role_db' > tb2.txt
tb_list=`cat tb2.txt`
for tb in $tb_list
do
   $MYSQL_CMD "USE pg_role_db;DELETE FROM $tb WHERE set_id=$SET_ID;"
done
echo "---------clear pg_role_db end---------"




echo "=========clear pg_mail_db begin ========="

$MYSQL_CMD "USE pg_mail_db;SHOW TABLES;" > tb1.txt
cat tb1.txt | grep -v 'Tables_in_pg_mail_db' > tb2.txt
tb_list=`cat tb2.txt`
for tb in $tb_list
do
   $MYSQL_CMD "USE pg_mail_db;DELETE FROM $tb WHERE set_id=$SET_ID;"
done
echo "---------clear pg_mail_db end---------"




echo "=========clear pg_game_cfg begin ========="

$MYSQL_CMD "USE pg_game_cfg;SHOW TABLES;" > tb1.txt
cat tb1.txt | grep -v 'Tables_in_pg_game_cfg' > tb2.txt
tb_list=`cat tb2.txt`
for tb in $tb_list
do
   $MYSQL_CMD "USE pg_game_cfg;DELETE FROM $tb WHERE set_id=$SET_ID;"
done
echo "---------clear pg_game_cfg end---------"




echo "=========clear pg_server_data_db begin ========="

$MYSQL_CMD "USE pg_server_data_db;SHOW TABLES;" > tb1.txt
cat tb1.txt | grep -v 'Tables_in_pg_server_data_db' > tb2.txt
tb_list=`cat tb2.txt`
for tb in $tb_list
do
   $MYSQL_CMD "USE pg_server_data_db;DELETE FROM $tb WHERE set_id=$SET_ID;"
done
echo "---------clear pg_server_data_db end---------"




echo "=========clear pg_log_db begin ========="

$MYSQL_CMD "USE pg_log_db;SHOW TABLES;" > tb1.txt
cat tb1.txt | grep -v 'Tables_in_pg_log_db' > tb2.txt
tb_list=`cat tb2.txt`
for tb in $tb_list
do
   $MYSQL_CMD "USE pg_log_db;DELETE FROM $tb WHERE set_id=$SET_ID;"
done
echo "---------clear pg_log_db end---------"

